package com.lanou.sinasports.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.android.volley.RequestQueue;
import com.android.volley.toolbox.ImageLoader;
import com.android.volley.toolbox.NetworkImageView;
import com.android.volley.toolbox.Volley;
import com.lanou.sinasports.R;
import com.lanou.sinasports.beans.SpecialDec;
import com.lanou.sinasports.utils.DoubleCache;

import java.util.List;

/**
 * Created by dllo on 16/1/23.
 */
public class SpecialDecAdapter extends BaseAdapter {

    private Context context;
    private List<SpecialDec> data;
    private RequestQueue queue;
    private ImageLoader imageLoader;

    public SpecialDecAdapter(Context context, List<SpecialDec> data) {
        this.context = context;
        this.data = data;
        queue= Volley.newRequestQueue(context);
        imageLoader=new ImageLoader(queue,new DoubleCache());
    }

    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int position) {
        return data.get(position);
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        SpeDectailViewHolder myViewHolder=null;
        if(convertView==null){
            convertView= LayoutInflater.from(context).inflate(R.layout.item_newsrecommend2, parent, false);
            myViewHolder=new SpeDectailViewHolder(convertView);
            convertView.setTag(myViewHolder);
        }else {
            myViewHolder= (SpeDectailViewHolder) convertView.getTag();
        }
            myViewHolder.stitle.setText(data.get(position).getStitle());
            myViewHolder.summary.setText(data.get(position).getSummary());
            myViewHolder.count.setText(data.get(position).getCount()+"评");

            myViewHolder.imageView.setImageUrl(data.get(position).getUrl(),imageLoader);

        return convertView;
    }

    class SpeDectailViewHolder {
        NetworkImageView imageView;
        TextView stitle;
        TextView summary;
        TextView count;
        public SpeDectailViewHolder(View view) {
           imageView= (NetworkImageView) view.findViewById(R.id.iv_item_newrecommend2);
            stitle= (TextView) view.findViewById(R.id.tv_item_newsrecommend2_stitle);
            summary= (TextView) view.findViewById(R.id.tv_item_newsrecommend2_summary);
            count= (TextView) view.findViewById(R.id.tv_item_newsrecommend2_count);

        }
    }
}
